package com.jiangyao.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiangyao.common.ApiResult;
import com.jiangyao.model.dto.CollectDto;
import com.jiangyao.model.entity.Collect;
import com.jiangyao.model.entity.UserExperience;
import com.jiangyao.model.vo.CollectVo;
import com.jiangyao.service.CollectService;
import com.jiangyao.service.JobDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.dozer.DozerBeanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.jiangyao.controller.BaseController;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 收藏与点赞 前端控制器
 * </p>
 *
 * @author xiangyan
 * @since 2020-08-15
 */
@RestController
@RequestMapping("/collect")
@Api(tags = "收藏相关")
public class CollectController extends BaseController {
    @Autowired
    private DozerBeanMapper dozerBeanMapper;

    @Autowired
    private CollectService collectService;

    @Autowired
    JobDataService jobDataService;

    @PostMapping("/collectLike")
    @ApiOperation(value = "收藏或点赞")
    public ApiResult<Boolean> collectLike(@Validated({CollectDto.Add.class})@RequestBody CollectDto collectDto){
        Collect collect = dozerBeanMapper.map(collectDto, Collect.class);
        collect.setCreateTime(new Date());
        collect.setUserId(getLoginSessionUserId());
        collectService.save(collect);
        if(collect.getType()==1){
            jobDataService.updateCollectNum(collect.getRelateId());
        }
        return ApiResult.success(true);
    }

    @PostMapping("/cancelCollectLike")
    @ApiOperation(value = "取消收藏或点赞")
    public ApiResult<Boolean> cancelCollectLike(@Validated({CollectDto.Edit.class})@RequestBody CollectDto dto){

        return ApiResult.success(collectService.cancelCollectLike(dto));
    }

    @PostMapping("/getUserJobList")
    @ApiOperation(value = "成员收藏或点赞的职位",notes = "必传：action")
    public ApiResult<List<CollectVo>> getUserJobList(@RequestBody CollectDto dto){
        return ApiResult.success(collectService.getUserJobList(dto));
    }

    @PostMapping("/getUserCoursewareList")
    @ApiOperation(value = "成员收藏或点赞的课件",notes = "必传：action")
    public ApiResult<List<CollectVo>> getUserCoursewareList(@RequestBody CollectDto dto){
        return ApiResult.success(collectService.getUserCoursewareList(dto));
    }

    @PostMapping("/getUserOrgList")
    @ApiOperation(value = "成员收藏或点赞的公司",notes = "必传：action")
    public ApiResult<List<CollectVo>> getUserOrgList(@RequestBody CollectDto dto){
        return ApiResult.success(collectService.getUserOrgList(dto));
    }
}

